import requests
def chat_with_ollama(prompt, model="deepseek-r1:1.5b"):
    url = "http://localhost:11434/api/generate"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "model": model,
        "prompt": prompt,
        "stream": False # 关闭流式返回，适合简单测试
    }
    try:
        response = requests.post(url, json=data, headers=headers)
        response.raise_for_status()
        result = response.json()
        print("模型回复：", result["response"])
    except requests.exceptions.RequestException as e:
        print("请求出错：", e)
    except Exception as e:
        print("其他错误：", e)

if __name__ == "__main__":
    test_prompt = "你好"
    chat_with_ollama(test_prompt)